<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
</head>
<body>

</body>
</html>
<?php 
	class User{
		private $name;
		private $sex;
		private $hobby;
		public function __construct($name="Tom",$sex="男",$hobby="上网"){
			$this->name=$name;
			$this->sex=$sex;
			$this->hobby=$hobby;
		}
		// //魔术方法
		// public function __set($propertyName,$propertyValue)
		// {
		// 	$this->propertyName=$propertyValue;
		// }
		// public function __get($propertyName){
		// 	return $this->$propertyName;
		// }
		public function getName(){
			return $this->name;
		}
		public function setName($name){
			$this->name=$name;
		}
		public function getSex(){
			return $this->sex;
		}
		public function setSex($sex){
			$this->sex=$sex;
		}
		public function getHobby(){
			return $this->hobby;
		}
		public function setHobby($hobby){
			$this->hobby=$hobby;
		}
		public function display(){
			echo "<br>".$this->name."的性别是：".$this->sex;
		}
	}
	//实例化对象
	$u1=new User("Jane","女");
	$u1->display();
	$u1->setName("James");
	//$u1->__set("name","James");
	$u1->setSex("男");
	//$u1->__set("sex","男");
	//$u1->__set("hobby","游泳");
	$u1->display();
	//
	$u2=new User();
	$u2->setName("Pool");
	$u2->setSex("男");
	$u2->setHobby("游泳");
	echo "<br>姓名是:".$u2->getName();
	//echo "<br>姓名是：".$u2->__get("name");
	echo "<br>性别是:".$u2->getSex();
	//echo "<br>性别是：".$u2->__get("sex");
	echo "<br>爱好是:".$u2->getHobby();
?>

 ?>